package design.pattern.prototype.apply2;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/**
 * @author AtoVio, Winter Yuan
 */
public class CitationTest {
    public static void main(String[] args) throws Exception {
        Citation obj1 = new Citation();
        Student stu1 = new Student("李飞", 1);
        obj1.setStudent(stu1);

        // 创建对象输出流
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("D:/WorkSpace/IDEA/design-pattern/withing-files/obj-out/a.txt"));
        // 写对象
        oos.writeObject(obj1);
        // 释放资源
        oos.close();

        // 创建对象输入流
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("D:/WorkSpace/IDEA/design-pattern/withing-files/obj-out/a.txt"));
        Citation obj2 = (Citation) ois.readObject();
        ois.close();

        // 修改克隆体Student属性，查看深克隆效果
        obj2.getStudent().setName("张明");

        System.out.println(obj1);
        System.out.println(obj2);
    }
}
